<template>
  <div class="swiper-container" ref="Carousel">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="Carousel in list" :key="Carousel.id">
        <img :src="Carousel.imgUrl" />
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
  </div>
</template>

<script>
import "swiper/swiper-bundle.min.css";
import Swiper from "swiper/swiper-bundle";
export default {
  props: ["list"],
  data() {
    return {};
  },
  watch: {
    //list是轮播图数据
    list: {
      immediate: true, //页面初始化的时候就调用一次handler()
      handler() {
        this.$nextTick(() => {
          var mySwiper = new Swiper(".swiper-container", {
            direction: "horizontal", // 水平切换选项
            loop: true, // 循环模式选项
            autoplay: {
              //自动切换的时间间隔（单位ms），不设定该参数slide不会自动切换。
              delay: 2000,
              //用户操作swiper之后自动切换不会停止，每次都会重新启动autoplay
              disableOnInteraction: false,
            },

            // 如果需要分页器
            pagination: {
              el: ".swiper-pagination",
              clickable: true, //可点击
              type: "bullets", //默认样式 小圆点, 还可选其他形状
            },

            // 如果需要前进后退按钮
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
          });
        });
      },
    },
  },
};
</script>

<style lang="less" scoped>
.swiper-container {
  z-index: 0;
  .swiper-slide {
    img {
      width: 1200px;
      height: 446px;
    }
  }
}
</style>